package com.webmuseum.client;

import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.DisclosurePanel;
import com.google.gwt.user.client.ui.IntegerBox;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.LongBox;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.Widget;
import com.google.gwt.user.datepicker.client.DatePicker;
import com.sun.java.swing.plaf.windows.WindowsBorders;

public class CloneManager 
{
	private static CloneManager mInstance = null;
	
	private CloneManager()
	{
		
		
	}
	
	public static CloneManager getInstance()
	{
		if(mInstance == null)
		{
			mInstance = new CloneManager();
		}

		return mInstance;
	}
	
	public Widget cloneWidget(Widget aWidget)
	{
		Widget clone = null;
		//Window.alert("TYPE IS "+ aWidget.getClass().toString());
		if(aWidget instanceof Label)
		{
			Label l = new Label();
			l.setText(((Label) aWidget).getText());
			l.setTitle(((Label) aWidget).getTitle());
			clone = l;
		}
		else if(aWidget instanceof TextBox)
		{
			TextBox t = new TextBox();
			t.setText(((TextBox)aWidget).getText());
			clone = t;
		}
		else if(aWidget instanceof DatePicker)
		{
			DatePicker d = new DatePicker();
			d.setValue(((DatePicker)aWidget).getValue());
			clone = d;
		}
		else if(aWidget instanceof IntegerBox)
		{
			IntegerBox b = new IntegerBox();
			b.setValue(((IntegerBox) aWidget).getValue());
			clone = b;
		}
		else if(aWidget instanceof LongBox)
		{
			LongBox b = new LongBox();
			b.setValue(((LongBox) aWidget).getValue());
			clone = b;
		}
		else if(aWidget instanceof UIMultiContainer)
		{
			clone = ((UIMultiContainer)aWidget).clone();
		}
		else if(aWidget instanceof UIContainer)
		{
			clone = ((UIContainer)aWidget).clone();
		}
		else if(aWidget instanceof ParagraphContent)
		{
			clone = ((ParagraphContent)aWidget).clone();
		}
		else if(aWidget instanceof SimpleFieldContent)
		{
			clone = ((SimpleFieldContent)aWidget).clone();
		}
		else if(aWidget instanceof StructuredFieldContent)
		{
			clone = ((StructuredFieldContent)aWidget).clone();
		}
		else if(aWidget instanceof SubFieldContent)
		{
			clone = ((SubFieldContent)aWidget).clone();
		}
		else if(aWidget instanceof DisclosurePanel)
		{
			DisclosurePanel d = new DisclosurePanel(((DisclosurePanel)aWidget).getHeaderTextAccessor().getText());
			//d.setHeader( cloneWidget( ((DisclosurePanel)aWidget).getHeader()) );
			d.setTitle( ((DisclosurePanel)aWidget).getTitle());
			d.setContent( cloneWidget( ((DisclosurePanel)aWidget).getContent()) );
			clone = d;
		}
		
		return clone;
	}
	

}
